package com.venus.controller;

import com.github.pagehelper.PageInfo;
import com.venus.entity.Menu;
import com.venus.entity.Page;
import com.venus.service.MenuService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by admin on 16/9/17.
 */
@Controller
@RequestMapping("/menu")
public class MenuController {

    private static final Logger LOGGER = LoggerFactory.getLogger(BaseController.class);

    @Resource
    private MenuService menuService;

	@RequestMapping("addMenu")
    public String addMenu(){
	    return "base/manage";
    }

    @RequestMapping("getAllParentNodeInfo")
    @ResponseBody
    public List<Menu> getAllParentNodeInfo(){
        return menuService.getAllParentNodeInfo();
    }
    @RequestMapping("addMenuForm")
    @ResponseBody
    public Map<String, String> addMenuForm(@RequestParam() Map<String, Object> params, Menu menu){
        Map<String, String> result = new HashMap<>();
        menuService.addMenu(menu);
        LOGGER.info(params.toString());
        result.put("result", "success");
        return result;
    }
    @RequestMapping("getMenuListByPage")
    public ModelAndView getMenuListByPage(ModelAndView mav,Page page,Menu menu){
        PageInfo<Menu> pages =  menuService.findMenusByPageList(page);
        mav.addObject("menu",pages);
        mav.setViewName("/base/rule");
        return mav;
    }
}
